<?php

 if(!__CFG_ADMIN_PANEL)
  {

    if(isBlank($_GET[$CONFIG['SiteLangVarName']]))
    {
      $_GET[$CONFIG['SiteLangVarName']] = $CONFIG['SiteLanguage'];
    }
    define('__LANG', $_GET[$CONFIG['SiteLangVarName']]);
    define('__FLANG', "_".__LANG);
    $sID->assign("LANG", __LANG);

    $SITE_LANGS = $LANGS = getTableAsArrayByKeyField($_SQL_TABLE['language'], 'code', 'sorting', array("active = 'y'", "site_lang = 'y'"));
    if(isEmptyArr($LANGS) || isBlank($LANGS[__LANG]['code']) || !is_file(__CFG_PATH_LANGUAGES_GENERATED.$LANGS[__LANG]['filename']))
    {      foreach($LANGS as $code => $arr)
      {
   	    showMessageAlertJVSC($CONFIG['ErrorLanguageInactive']);
   	    $URL_WITHOUT_LANG = getSameUriWithoutLangPath(__LANG);
   	    go_toJVSC("/".$code.$URL_WITHOUT_LANG);
   	    exit;
   	  }
    }
    else
    {
      include_once __CFG_PATH_LANGUAGES_GENERATED.$LANGS[__LANG]['filename'];
      $sID->assign("langPath", "/".__LANG);
      $URL_WITHOUT_LANG = getSameUriWithoutLangPath(__LANG);
      $sID->assign("URL_WITHOUT_LANG", $URL_WITHOUT_LANG);
    }
  }
  else
  {
    if(!isBlank($_GET[$CONFIG['AdminLangVarName']]))
    {
      $sID->assign("ADMIN_LANG", $_GET[$CONFIG['AdminLangVarName']]);
    }
    elseif(isBlank($_GET[$CONFIG['AdminLangVarName']]) && isBlank($sID->fetch("ADMIN_LANG")))
    {
      $_GET[$CONFIG['AdminLangVarName']] = $CONFIG['AdminLanguageCode'];
    }
    elseif(isBlank($_GET[$CONFIG['AdminLangVarName']]) && !isBlank($sID->fetch("ADMIN_LANG")))
    {      $_GET[$CONFIG['AdminLangVarName']] = $sID->fetch("ADMIN_LANG");
    }
    define('__LANG', $_GET[$CONFIG['AdminLangVarName']]);
    define('__FLANG', "_".__LANG);

    $LANGS = getTableAsArrayByKeyField($_SQL_TABLE['language'], 'code', 'sorting', array("active = 'y'", "admin_lang = 'y'"));
    $SITE_LANGS = getTableAsArrayByKeyField($_SQL_TABLE['language'], 'code', 'sorting', array("active = 'y'", "site_lang = 'y'"));
    if(isEmptyArr($LANGS) || isBlank($LANGS[__LANG]['code']) || !is_file(__CFG_PATH_LANGUAGES_GENERATED.$LANGS[__LANG]['filename']))
    {
      foreach($LANGS as $code => $arr)
      {
   	    showMessageAlertJVSC($CONFIG['ErrorLanguageInactive']);
   	    $URL_WITHOUT_LANG = getSameUriWithoutLangVar(__LANG, $CONFIG['AdminLangVarName']);
   	    go_toJVSC($URL_WITHOUT_LANG."&".$CONFIG['AdminLangVarName']."=".$code);
   	    exit;
   	  }
    }
    else
    {
      require_once __CFG_PATH_LANGUAGES_GENERATED.$LANGS[__LANG]['filename'];
      $URL_WITHOUT_LANG = getSameUriWithoutLangVar(__LANG, $CONFIG['AdminLangVarName']);
      $sID->assign("URL_WITHOUT_LANG", $URL_WITHOUT_LANG);
    }
  }

?>